﻿using System.Threading;

namespace Chapter1
{
    public class FoobarService
    {
        internal static int _lastId;

        public int Id { get; }

        /***
         *  Interlocked.Increment(ref _lastId);
         * 以原子操作的形式递增指定变量的值并存储结果
         * */
        private FoobarService() => Id = Interlocked.Increment(ref _lastId);

        public static FoobarService Create() => new FoobarService();
    }
}
